package com.cskaoyan.controller.back.admin;

import com.cskaoyan.bean.bo.back.admin.AdminBo;
import com.cskaoyan.bean.po.*;
import com.cskaoyan.bean.vo.back.BaseRespVo;
import com.cskaoyan.bean.vo.back.admin.BaseDataVo;
import com.cskaoyan.service.back.admin.AdminService;
import com.cskaoyan.util.ValidationUtils;
import lombok.SneakyThrows;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 用户管理控制器
 *
 * @author 李然
 * @date 2022/10/12
 */
@RestController
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * @return data为0的json
     */

    @GetMapping("profile/nnotice")
    public BaseRespVo profileNotice() {
        return BaseRespVo.ok(0);
    }

    /**
     * 获取用户列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
    @RequiresPermissions("admin:user:list")
    @GetMapping("user/list")
    public BaseRespVo userList(AdminBo parameter) {
        BaseDataVo<MarketUser> responseData = adminService.getUserListByParam(parameter);
        return BaseRespVo.ok(responseData);
    }

    @RequiresPermissions("admin:user:list")
    @GetMapping("user/detail")
    public BaseRespVo userDetail(Integer id) {
        MarketUser responseData = adminService.getUserById(id);
        return BaseRespVo.ok(responseData);
    }

    /**
     * 地址列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
    @RequiresPermissions("admin:address:list")
    @GetMapping("address/list")
    public BaseRespVo addressList(AdminBo parameter) {
        BaseDataVo<MarketAddress> responseData = adminService.getAddressList(parameter);
        return BaseRespVo.ok(responseData);
    }


    /**
     * 收藏列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
    @RequiresPermissions("admin:collect:list")
    @GetMapping("collect/list")
    public BaseRespVo collectList(AdminBo parameter) {
        BaseDataVo<MarketCollect> responseData = adminService.getCollectList(parameter);
        return BaseRespVo.ok(responseData);
    }

    /**
     * 足迹列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
    @RequiresPermissions("admin:footprint:list")
    @GetMapping("footprint/list")
    public BaseRespVo footprintList(AdminBo parameter) {
        BaseDataVo<MarketFootprint> responseData = adminService.getFootprintList(parameter);
        return BaseRespVo.ok(responseData);
    }

    /**
     * 历史记录列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
@RequiresPermissions("admin:history:list")
    @GetMapping("history/list")
    public BaseRespVo historyList(AdminBo parameter) {
        BaseDataVo<MarketSearchHistory> responseData = adminService.getHistoryList(parameter);
        return BaseRespVo.ok(responseData);
    }

    /**
     * 反馈列表
     *
     * @param parameter 根据需求获取参数列表
     * @return 返回带有所需数据的json
     */
@RequiresPermissions("admin:feedback:list")
    @GetMapping("feedback/list")
    public BaseRespVo feedbackList(AdminBo parameter) {
        BaseDataVo<MarketFeedback> responseData = adminService.getFeedbackList(parameter);
        return BaseRespVo.ok(responseData);
    }

    @SneakyThrows
    @RequiresPermissions("admin:user:list")
    @PostMapping("user/update")
    public BaseRespVo userUpdate(@RequestBody @Validated MarketUser parameter, BindingResult bindingResult) {
        ValidationUtils.valid(bindingResult);
        adminService.updateUserByJsonParam(parameter);
        return BaseRespVo.ok(1);
    }
}
